package org.x4444.trans;

import java.io.IOException;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;

public class TransReducer extends Reducer<Text, Text, NullWritable, Text> {

    NullWritable k = NullWritable.get();
    
    MultipleOutputs<NullWritable, Text> mos;
    
    @Override
    protected void setup(Reducer<Text, Text, NullWritable, Text>.Context context) throws IOException, InterruptedException {
       mos = new MultipleOutputs<NullWritable, Text>(context);
    }
    
    @Override
    protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, NullWritable, Text>.Context context) throws IOException, InterruptedException {
        String keyStr = key.toString();

        for (Text value : values) {
            mos.write("seq", k, value, keyStr);
            //context.write(key, value);
        }
    }
    
    @Override
    protected void cleanup(org.apache.hadoop.mapreduce.Reducer<Text, Text, NullWritable, Text>.Context context) throws IOException, InterruptedException {
        mos.close();
    }
}
